package com.yilin.medical.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yilin.medical.R;
import com.yilin.medical.fragment.ZhongLiuFragment;
import com.yilin.medical.views.RadioGroupContain;

/*
 *病例讨论 
 */
public class BingLiTaoLunActivity extends BaseActivity implements
		OnPageChangeListener {

	private TextView mTextViewBingLiTaoLun, mTextViewWoFaBuDe,
			mTextViewWoCanYuDe;
	private RelativeLayout mRelativeLayoutBingLiTaoLun,
			mRelativeLayoutWoFaBuDe, mRelativeLayoutWoCanYuDe;
	private ViewPager mViewPager;
	private FragmentPagerAdapter mAdapter;
	private List<Fragment> mDatas;
	private Context context;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentViewWithTitle(R.layout.activity_casediscuss);
		RadioGroupContain contain = (RadioGroupContain) findViewById(R.id.radio_contain);
		List<String> mlist = new ArrayList<String>();
		if (mlist.size() > 0) {
			mlist.clear();
		}
		mlist.add("肿瘤");
		mlist.add("心血管");
		mlist.add("眼科");
		mlist.add("消化");
		mlist.add("内分泌");
		mlist.add("更多");
		contain.init(this,mlist);
		context = this;
		initView();
		initData();
		registerLintener();
	}

	private void initView() {
		mTitle.getTitle().setText("病例讨论");
		mTextViewBingLiTaoLun = (TextView) findViewById(R.id.tv_binglitaolun);
		mTextViewWoFaBuDe = (TextView) findViewById(R.id.tv_wofabude);
		mTextViewWoCanYuDe = (TextView) findViewById(R.id.tv_wocanyude);

		mRelativeLayoutBingLiTaoLun = (RelativeLayout) findViewById(R.id.rl_binglitaolun);
		mRelativeLayoutWoFaBuDe = (RelativeLayout) findViewById(R.id.rl_wofabude);
		mRelativeLayoutWoCanYuDe = (RelativeLayout) findViewById(R.id.rl_wocanyude);
		mViewPager = (ViewPager) findViewById(R.id.pager);

		mTitle.setImageView(R.drawable.person_light, View.VISIBLE, this);
	}

	private void registerLintener() {
		mViewPager.setOnPageChangeListener(this);
		mRelativeLayoutBingLiTaoLun.setOnClickListener(this);
		mRelativeLayoutWoFaBuDe.setOnClickListener(this);
		mRelativeLayoutWoCanYuDe.setOnClickListener(this);
		mTitle.setImageView(View.VISIBLE, this);
	}

	private void initData() {
		mDatas = new ArrayList<Fragment>();

		ZhongLiuFragment tab01 = new ZhongLiuFragment();
		ZhongLiuFragment tab02 = new ZhongLiuFragment();
		ZhongLiuFragment tab03 = new ZhongLiuFragment();

		mDatas.add(tab01);
		mDatas.add(tab02);
		mDatas.add(tab03);

		mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
			@Override
			public int getCount() {
				return mDatas.size();
			}

			@Override
			public Fragment getItem(int arg0) {
				return mDatas.get(arg0);
			}
		};
		mViewPager.setAdapter(mAdapter);
	}



	@Override
	public void onClick(View v) {
		Intent intent;
		super.onClick(v);
		switch (v.getId()) {
		case R.id.title_iv:
			intent = new Intent(context, FaBuBingLiActivity.class);
			startActivity(intent);
			break;
		case R.id.rl_binglitaolun:
			mViewPager.setCurrentItem(0, true);
			break;
		case R.id.rl_wofabude:
			mViewPager.setCurrentItem(1, true);
			break;
		case R.id.rl_wocanyude:
			mViewPager.setCurrentItem(2, true);
			break;
		}
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
	}

	@Override
	public void onPageSelected(int position) {
		resetTextView();
		switch (position) {
		case 0:

			mTitle.getTitle().setText("病例讨论");
			mTextViewBingLiTaoLun.setTextColor(Color.parseColor("#ffffff"));
			mRelativeLayoutBingLiTaoLun.setBackgroundColor(Color
					.parseColor("#68B3DE"));
			break;
		case 1:
			mTitle.getTitle().setText("我发布的");
			mTextViewWoFaBuDe.setTextColor(Color.parseColor("#ffffff"));
			mRelativeLayoutWoFaBuDe.setBackgroundColor(Color
					.parseColor("#68B3DE"));
			break;
		case 2:
			mTitle.getTitle().setText("我参与的");
			mTextViewWoCanYuDe.setTextColor(Color.parseColor("#ffffff"));
			mRelativeLayoutWoCanYuDe.setBackgroundColor(Color
					.parseColor("#68B3DE"));
			break;
		}

	}

	private void resetTextView() {// #2B95D3蓝色
		mTextViewBingLiTaoLun.setTextColor(Color.BLACK);
		mRelativeLayoutBingLiTaoLun.setBackgroundColor(Color
				.parseColor("#ffffff"));
		mTextViewWoFaBuDe.setTextColor(Color.BLACK);
		mRelativeLayoutWoFaBuDe.setBackgroundColor(Color.parseColor("#ffffff"));
		mTextViewWoCanYuDe.setTextColor(Color.BLACK);
		mRelativeLayoutWoCanYuDe
				.setBackgroundColor(Color.parseColor("#ffffff"));
	}

}
